/*
 * @Author: lineCode 1145938682@qq.com
 * @Date: 2025-02-13 22:41:17
 * @LastEditors: lineCode 1145938682@qq.com
 * @LastEditTime: 2025-02-18 23:01:55
 * @FilePath: /backend/shorthand-modules/shorthand-modules-content/src/main/java/com/angus/modules/content/repository/CNQuestionRepository.java
 */
package com.angus.modules.content.repository;

import com.angus.modules.content.domain.CNCourseQuestion;
import com.angus.modules.content.mapper.CNCourseQuestionMapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Objects;

/**
 * @author liyanan
 * @date 2024/10/29 4:19 PM
 * @description
 */
@Repository
public class CNQuestionRepository extends ServiceImpl<CNCourseQuestionMapper, CNCourseQuestion> {


    public List<CNCourseQuestion> getQuestionList(String courseCode, Integer questionType, Long groupId, Integer unitNum) {

        return baseMapper.selectList(Wrappers.lambdaQuery(CNCourseQuestion.class)
                .eq(CNCourseQuestion::getCourseCode, courseCode)
                .eq(CNCourseQuestion::getUnitNum,unitNum)
                .eq(CNCourseQuestion::getQuestionType, questionType)
                .eq(Objects.nonNull(groupId), CNCourseQuestion::getGroupId, groupId)
                .eq(CNCourseQuestion::getDelFlag, 0));
    }

    public Boolean getQuestion(String courseCode, Long groupId, String groupFlag, Integer questionType) {
        Long count = baseMapper.selectCount(Wrappers.lambdaQuery(CNCourseQuestion.class)
                .eq(CNCourseQuestion::getCourseCode, courseCode)
                .eq(CNCourseQuestion::getQuestionType, questionType)
                .eq(CNCourseQuestion::getGroupId, groupId)
                .eq(CNCourseQuestion::getGroupFlag, groupFlag)
                .eq(CNCourseQuestion::getDelFlag, 0));
        return count > 0;
    }

    public Boolean getQuestionByCourse(String courseCode, Integer questionType) {
        Long count = baseMapper.selectCount(Wrappers.lambdaQuery(CNCourseQuestion.class)
                .eq(CNCourseQuestion::getCourseCode, courseCode)
                .eq(CNCourseQuestion::getQuestionType, questionType)
                .eq(CNCourseQuestion::getDelFlag, 0));
        return count > 0;
    }
}
